package com.baoteng.rbspy.model.privy.group;

import java.util.List;
import java.util.Optional;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.baoteng.rbspy.annotation.JsoupProperty;
import com.baoteng.rbspy.model.privy.PersonAddress;
import com.baoteng.rbspy.model.privy.PersonContact;
import com.baoteng.rbspy.util.JsoupUtil;
import com.google.common.collect.Lists;

public class GroupUpdatePO {

	@JsoupProperty(tag = "input[name=token]")
	String token;
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.firstDate]")
	String firstDate;
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.mergeCode]")
	String mergeCode;
	/**
	 * 2 "审批通过"; 1 "待审批"; 3 "审批不通过"; 0 "未提交审批";
	 * 
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.auditStatus]")
	String auditStatus;
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.auditType]")
	String auditType;
	/**
	 * 1 "有效"; 0 "无效"; "其他";
	 * 
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.validStatus]")
	String validStatus;
	/**
	 * 客户编码
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.customerCode]")
	String customerCode;
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.versionNo]")
	String versionNo;
	/**
	 * 中文名
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.customerCName]")
	String customerCName;
	/**
	 * 英文名
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.customerEName]")
	String customerEName;
	/**
	 * 营业执照代码
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.businessLicense]")
	String businessLicense;
	/**
	 * 营业执照有效期
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.dateValid]")
	String dateValid;
	/**
	 * 组织机构代码
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.organizeCode]")
	String organizeCode;
	/**
	 * 组织机构代码有效期
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.orgDateValid]")
	String orgDateValid;
	/**
	 * 统一社会信用代码：
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.unifiedSocialCreditCode]")
	String unifiedSocialCreditCode;
	/**
	 * 统一社会信用代码有效期
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.creditDateValid]")
	String creditDateValid;
	/**
	 * 税务代码
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.revenueCode]")
	String revenueCode;
	/**
	 * 企业工商代码
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.industryCode]")
	String industryCode;
	
	/**
	 * 企业性质/所有制代码
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.businessSort]")
	String businessSort;
	
	/**
	 * 国籍
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.nationality]")
	String nationality="CHN";
	/**
	 * 住所
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.residence]")
	String residence;
	/**
	 * 居民与非居民 A--居民 B--非居民
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.resident]")
	String resident="A";
	/**
	 * 是否普惠融资带动客户： 1--是 0--否
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.financeFlag]")
	String financeFlag;
	/**
	 * 风险等级： 1--高 2--中 3--低
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.creditLevel]")
	String creditLevel="3";
	/**
	 * 送审批说明
	 */
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.submitDescription]")
	String submitDescription;
	@JsoupProperty(tag = "input[name=prpDcustomerGroup.email]")
	String email;
	
	List<PersonContact> contacts;
	List<PersonAddress> addresses;
	
	Taxpayer taxpayer;

	public void parser(Element doc) {
		contacts = Optional.ofNullable(contacts).orElse(Lists.newArrayList());
		Element element = doc.getElementById("PhoneGroupEdit");
		if (element != null) {
			Elements elements = element.select("tbody>tr");
			elements.forEach(e -> {
				PersonContact itemPO = new PersonContact();
				JsoupUtil.newInstance().parse(e, itemPO);
				contacts.add(itemPO);
			});
		}
		addresses = Optional.ofNullable(addresses).orElse(Lists.newArrayList());
		Element _element = doc.getElementById("AddressGroupEdit");
		if (_element != null) {
			Elements elements = _element.select("tbody>tr");
			elements.forEach(e -> {
				Elements _elements = e.select("input[name=buttonInsert]");
				if(_elements==null || _elements.isEmpty()) {
					PersonAddress itemPO = new PersonAddress();
					JsoupUtil.newInstance().parse(e, itemPO);
					addresses.add(itemPO);
				}
			});
		}
		taxpayer = new Taxpayer();
		Element taxElement = doc.getElementById("taxpayer_body");
		if (_element != null) {
			JsoupUtil.newInstance().parse(taxElement, taxpayer);
		}
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getFirstDate() {
		return firstDate;
	}

	public void setFirstDate(String firstDate) {
		this.firstDate = firstDate;
	}

	public String getMergeCode() {
		return mergeCode;
	}

	public void setMergeCode(String mergeCode) {
		this.mergeCode = mergeCode;
	}

	public String getAuditStatus() {
		return auditStatus;
	}

	public void setAuditStatus(String auditStatus) {
		this.auditStatus = auditStatus;
	}

	public String getAuditType() {
		return auditType;
	}

	public void setAuditType(String auditType) {
		this.auditType = auditType;
	}

	public String getValidStatus() {
		return validStatus;
	}

	public void setValidStatus(String validStatus) {
		this.validStatus = validStatus;
	}

	public String getCustomerCode() {
		return customerCode;
	}

	public void setCustomerCode(String customerCode) {
		this.customerCode = customerCode;
	}

	public String getVersionNo() {
		return versionNo;
	}

	public void setVersionNo(String versionNo) {
		this.versionNo = versionNo;
	}

	public String getCustomerCName() {
		return customerCName;
	}

	public void setCustomerCName(String customerCName) {
		this.customerCName = customerCName;
	}

	public String getCustomerEName() {
		return customerEName;
	}

	public void setCustomerEName(String customerEName) {
		this.customerEName = customerEName;
	}

	public String getBusinessLicense() {
		return businessLicense;
	}

	public void setBusinessLicense(String businessLicense) {
		this.businessLicense = businessLicense;
	}

	public String getDateValid() {
		return dateValid;
	}

	public void setDateValid(String dateValid) {
		this.dateValid = dateValid;
	}

	public String getOrganizeCode() {
		return organizeCode;
	}

	public void setOrganizeCode(String organizeCode) {
		this.organizeCode = organizeCode;
	}

	public String getOrgDateValid() {
		return orgDateValid;
	}

	public void setOrgDateValid(String orgDateValid) {
		this.orgDateValid = orgDateValid;
	}

	public String getUnifiedSocialCreditCode() {
		return unifiedSocialCreditCode;
	}

	public void setUnifiedSocialCreditCode(String unifiedSocialCreditCode) {
		this.unifiedSocialCreditCode = unifiedSocialCreditCode;
	}

	public String getCreditDateValid() {
		return creditDateValid;
	}

	public void setCreditDateValid(String creditDateValid) {
		this.creditDateValid = creditDateValid;
	}

	public String getRevenueCode() {
		return revenueCode;
	}

	public void setRevenueCode(String revenueCode) {
		this.revenueCode = revenueCode;
	}

	public String getIndustryCode() {
		return industryCode;
	}

	public void setIndustryCode(String industryCode) {
		this.industryCode = industryCode;
	}

	public String getBusinessSort() {
		return businessSort;
	}

	public void setBusinessSort(String businessSort) {
		this.businessSort = businessSort;
	}

	public String getNationality() {
		return nationality;
	}

	public void setNationality(String nationality) {
		this.nationality = nationality;
	}

	public String getResidence() {
		return residence;
	}

	public void setResidence(String residence) {
		this.residence = residence;
	}

	public String getResident() {
		return resident;
	}

	public void setResident(String resident) {
		this.resident = resident;
	}

	public String getFinanceFlag() {
		return financeFlag;
	}

	public void setFinanceFlag(String financeFlag) {
		this.financeFlag = financeFlag;
	}

	public String getCreditLevel() {
		return creditLevel;
	}

	public void setCreditLevel(String creditLevel) {
		this.creditLevel = creditLevel;
	}

	public String getSubmitDescription() {
		return submitDescription;
	}

	public void setSubmitDescription(String submitDescription) {
		this.submitDescription = submitDescription;
	}

	public List<PersonContact> getContacts() {
		return contacts;
	}

	public void setContacts(List<PersonContact> contacts) {
		this.contacts = contacts;
	}

	public List<PersonAddress> getAddresses() {
		return addresses;
	}

	public void setAddresses(List<PersonAddress> addresses) {
		this.addresses = addresses;
	}

	public Taxpayer getTaxpayer() {
		return taxpayer;
	}

	public void setTaxpayer(Taxpayer taxpayer) {
		this.taxpayer = taxpayer;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

}
